<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<div class="topadd_pop ty_pop">
    <div class="popbg"></div>
    <div class="topadd_inner">
        <ul>
            <li><a  id="scbutton" href="javascript:;">扫一扫</a></li>
            <li><a  id="addDevice"href="javascript:;">增加设备</a></li>
            <li><a href="${basePath}wechat/operate/place/addView">增加场地</a></li>
        </ul>
    </div>
</div>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
	wx.config({
	    debug: false,
	    appId: '${jsret.appid}',
	    timestamp:'${jsret.timestamp}',
	    nonceStr: '${jsret.nonceStr}',
	    signature: '${jsret.signature}',
	    jsApiList: [  
	      'scanQRCode'
	    ]
	});
	wx.ready(function(){
        $("#scbutton").on("click", function(){
            wx.scanQRCode({
                needResult: 1,
                scanType: ["qrCode","barCode"],
                success: function (res) {
                     var result = res.resultStr;
                        window.location = "${basePath}wechat/operate/device/addView/"+result;

                }
            });
        });
	});

    $("#addDevice").on("click", function(){
        $.ajax({
            url:'${basePath}wechat/operate/place/checkUserPlace',
            type : 'GET',
            error: function (response) {
                ViewHelper.func.ajaxWechatErrorMessage(response);
            },
            success: function (ret) {
                console.log('返回:'+ret.placeBoolean);
                if(ret.placeBoolean == true){
                    scanQrCode();
                }else{
                    window.location = "${basePath}wechat/operate/place/addView";
                }
            }
        });
    });


    function scanQrCode(){
        wx.scanQRCode({
            needResult: 1,
            scanType: ["qrCode","barCode"],
            success: function (res) {
                var result = res.resultStr;
                window.location = "${basePath}wechat/operate/device/addView/"+result;
            }
        });
    }

</script>

